package com.ruoyi.printer.task;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.printer.domain.PrinterFile;
import com.ruoyi.printer.service.IPrinterFileService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 定时移除文件
 * @author yanyi
 */
@Slf4j
@Component("deleteFileTask")
public class DeleteFileTask {
    @Autowired
    IPrinterFileService printerFileService;

    /**
     * 根据文件状态和创建时间删除文件
     * @param fileStatus 文件状态
     * @param createTime 创建时间
     */
    public void delByStatusAndTime(Integer fileStatus, String createTime)
    {
        if (fileStatus == 0) {
            throw new ServiceException("删除文件数据异常", HttpStatus.BAD_REQUEST);
        }
        LambdaQueryWrapper<PrinterFile> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(PrinterFile::getFileStatus, fileStatus);
        queryWrapper.le(PrinterFile::getCreateTime, createTime);
        List<PrinterFile> fileList = printerFileService.list(queryWrapper);
        log.info("delByStatusAndTime：" + fileList.size());
    }

    /**
     * 根据文件状态删除文件
     */
    public void del()
    {
        List<PrinterFile> fileList = printerFileService.list(new LambdaQueryWrapper<PrinterFile>().eq(PrinterFile::getFileStatus, 1));
        log.info("delByStatus：" + fileList.size());
    }

    /**
     * 删除文件
     * @param fileList 文件列表
     */
    public void remove(List<PrinterFile> fileList) {

    }
}
